﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace dri8.local
{
	public class lStr : hcom.hString
	{
		/// <summary>
		/// 如果name有值，取name，否则取ip并把最后一位换成*号
		/// </summary>
		/// <param name="ip">数据库中的ip</param>
		/// <param name="name">数据库中的name</param>
		/// <returns></returns>
		public string getName(object ip, object name)
		{
			if (name == DBNull.Value)
			{
				string pattern = "(\\d+.\\d+.\\d+.)\\d+";
				Regex reg = new Regex(pattern, RegexOptions.IgnoreCase);
				return reg.Replace(ip.ToString(), "${1}*");
			}
			else
				return name.ToString();
		}

		/// <summary>
		/// 把文章和评论中的自定义符号转换成html标签
		/// </summary>
		/// <param name="str">原文本</param>
		/// <returns>转换后的文本</returns>
		public string convertHtml(string str)
		{
			string pattern = "\\{\\{(em\\d+)\\}\\}";
			Regex reg = new Regex(pattern, RegexOptions.IgnoreCase);
			string ss = reg.Replace(str, " <img src='/images/bq/${1}.gif' /> ");
			pattern = "\\{\\(([^)]+)\\)\\}";
			reg = new Regex(pattern, RegexOptions.None);
			ss = reg.Replace(ss, "<${1}>");
			return ss;
		}
	}
}
